package com.chinasoft.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@SessionAttributes(names = {"age","gender"})
public class UserController {

    @RequestMapping("/servletApi")
    public String servletApi(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        System.out.println(request);
        System.out.println(response);
        System.out.println(session);
        return "page";
    }

    @RequestMapping("/headApi")
    public String headApi(@RequestHeader("accept-language") String headMsg){
        System.out.println(headMsg);

        return "page";
    }
    @RequestMapping("/cookieApi")
    public String cookieApi(@CookieValue("JSESSIONID") String jessionid){
        System.out.println(jessionid);

        return "page"; //D8C7DD042B2C9C7B8B0C594FC8530D8A
    }

    @RequestMapping("/sessionApi")
    public String sessionApi(@SessionAttribute("age") int age,
                             @SessionAttribute("gender") String gender){
        System.out.println("age = " + age);
        System.out.println("gender = " + gender);
        return "page"; //D8C7DD042B2C9C7B8B0C594FC8530D8A
    }

    @RequestMapping("/sessionApi2")
    public String sessionApi2(Model model){
        model.addAttribute("age",39);
        model.addAttribute("gender","male");

        return "page"; //D8C7DD042B2C9C7B8B0C594FC8530D8A
    }


}